<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>开发</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../css/style.css"/>
    <style>
        .empty{ text-align: center; padding: 120px 0; }
    </style>
</head>
<body>
    <div class="empty">开发</div>
    <button onclick="getLocation()">点击获取地址</button>
    <br/>
    <br/>
    <br/>


    <div id="container" style="display:none">
          <div><span>地址：</span><span id="address"></span></div>
          <div><span>维度：</span><span id="lat"></span></div>
          <div><span>精度：</span><span id="ing"></span></div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/zepto.min.js"></script>
<script type="text/javascript">

apiready = function () {

  // var baiduLocation = api.require('baiduLocation');
  // baiduLocation.getLocation(function(ret, err) {
  //     if (ret) {
  //         alert(JSON.stringify(ret));
  //     } else {
  //         alert(JSON.stringify(err));
  //     }
  // });
}


function getLocation() {
  $("#container").hide();
    var baiduLocation = api.require('baiduLocation');
  baiduLocation.getLocation(function(ret, err) {
      if (ret && ret.status) {
        var lat = ret.latitude;//纬度
           var lon = ret.longitude;//经度
           var t = ret.timestamp; //更新时间
           var str = '经度：'+ lon +'<br>';
           str += '纬度：'+ lat +'<br>';
           str += '更新时间：'+ t +'<br>';

          var apk = "oj84w44i4N9PzdcN96oPmkm6cu0eqIBE";
          var local = lat+","+lon;//经纬度;
          $.ajax({
            url:"http://api.map.baidu.com/geocoder/v2/",
            type:"post",
            dataType:"jsonp",
            callback:"renderReverse",
            data:{
              ak:"oj84w44i4N9PzdcN96oPmkm6cu0eqIBE",
              location:local,
              output:"json",//返回类型
              pois:0
            },success:function (data) {
              if(data.status==0){
                    var result = data.result;
                    var location =result.location;
                    var lat = location.lat;//维度
                    var ing = location.ing;//精度

                    var address = result.formatted_address;//地址
                    var country = result.addressComponent.country;//国家
                    var province = result.addressComponent.province;//省份
                    var city = result.addressComponent.city;//城市


                    $("#container").show();
                    $("#address").html(address);
                    $("#lat").html(lat);
                    $("#ing").html(lon);
              }else{

              }

            },error:function (request,ree) {
              alert(ree)
            }
          })

          //获取位置信息成功
      } else {
          alert(JSON.stringify(err));
      }
  });
}
</script>


</html>
